
package com.jf.cloud.live.controller.app;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.live.dto.LiveRoomBackDTO;
import com.jf.cloud.live.model.LiveRoomBack;
import com.jf.cloud.live.service.LiveRoomBackService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 直播回放
 *
 * @author zz
 * @date 2022-08-17 17:09:06
 */
@RestController("appLiveRoomBackController")
@RequestMapping("/live_room_back")
@Tag(name = "直播回放")
public class LiveRoomBackController {

    @Autowired
    private LiveRoomBackService liveRoomBackService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取直播回放列表" , description = "分页获取直播回放列表")
    public ServerResponseEntity<PageVO<LiveRoomBack>> page(@Valid PageDTO pageDTO) {
        PageVO<LiveRoomBack> liveRoomBackPage = liveRoomBackService.page(pageDTO);
        return ServerResponseEntity.success(liveRoomBackPage);
    }

    @GetMapping
    @Operation(summary = "获取直播回放" , description = "根据backId获取直播回放")
    public ServerResponseEntity<LiveRoomBack> getByBackId(@ParameterObject @RequestParam Long backId) {
        return ServerResponseEntity.success(liveRoomBackService.getByBackId(backId));
    }

    @PostMapping
    @Operation(summary = "保存直播回放" , description = "保存直播回放")
    public ServerResponseEntity<Void> save(@Valid @RequestBody LiveRoomBackDTO liveRoomBackDTO) {
        LiveRoomBack liveRoomBack = mapperFacade.map(liveRoomBackDTO, LiveRoomBack.class);
        liveRoomBackService.save(liveRoomBack);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新直播回放" , description = "更新直播回放")
    public ServerResponseEntity<Void> update(@Valid @RequestBody LiveRoomBackDTO liveRoomBackDTO) {
        LiveRoomBack liveRoomBack = mapperFacade.map(liveRoomBackDTO, LiveRoomBack.class);
        liveRoomBackService.update(liveRoomBack);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除直播回放" , description = "根据直播回放id删除直播回放")
    public ServerResponseEntity<Void> delete(@RequestParam Long backId) {
        liveRoomBackService.deleteById(backId);
        return ServerResponseEntity.success();
    }
}
